import { Injectable } from '@angular/core';
import {Router} from "@angular/router";
import {AdminInfo} from "./energy/api";

@Injectable({
  providedIn: 'root',
})
export class AdminService {
  public static admin:AdminInfo = null;
  constructor(private router:Router) {

  }

  setAdmin(admin:AdminInfo){
    AdminService.admin = admin;
  }

  getAdmin():AdminInfo{
    if(AdminService.admin==null)
      this.router.navigate(["/auth"]);
     return AdminService.admin;
  }

  hasLogin():boolean{
    return AdminService.admin!=null
  }

  logout(){
    AdminService.admin = null;
    this.router.navigate(["/auth"]);
  }
}
